home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 October / MACPOWER-1997-10.ISO.7z / MACPOWER-1997-10.ISO / AMUG / PROGRAMMING / Mac F2C 1.3.5.sit / Mac F2C 1.3.5 / Mac F2C Libraries / libF77 Sources / getenv_.c < prev    next >
C/C++ Source or Header  |  1995-09-09  |  1KB  |  64 lines

  1. #include "f2c.h"
  2.  
  3. /*
  4.  * getenv - f77 subroutine to return environment variables
  5.  *
  6.  * called by:
  7.  *    call getenv (ENV_NAME, char_var)
  8.  * where:
  9.  *    ENV_NAME is the name of an environment variable
  10.  *    char_var is a character variable which will receive
  11.  *        the current value of ENV_NAME, or all blanks
  12.  *        if ENV_NAME is not defined
  13.  */
  14.  
  15. #ifdef KR_headers
  16. VOID getenv_(fname, value, flen, vlen) char *value, *fname; ftnlen vlen, flen;
  17. #else
  18. void getenv_(char *fname, char *value, ftnlen flen, ftnlen vlen)
  19. #endif
  20. {
  21.  
  22. /* IMT 9Sep95  Macintosh doesn't have any environment variables */
  23.  
  24. #if defined(SPM_F2C) || defined(TPM_F2C) || defined(CW_F2C) || defined(MPW_CW_F2C)
  25.  
  26.     while( --vlen >= 0 )                /* On Mac just fill it with blanks */
  27.         *value++ = ' ';
  28.         
  29. #else    
  30.  
  31. extern char **environ;
  32. register char *ep, *fp, *flast;
  33. register char **env = environ;
  34.  
  35. flast = fname + flen;
  36. for(fp = fname ; fp < flast ; ++fp)
  37.     if(*fp == ' ')
  38.         {
  39.         flast = fp;
  40.         break;
  41.         }
  42.  
  43. while (ep = *env++)
  44.     {
  45.     for(fp = fname; fp<flast ; )
  46.         if(*fp++ != *ep++)
  47.             goto endloop;
  48.  
  49.     if(*ep++ == '=') {    /* copy right hand side */
  50.         while( *ep && --vlen>=0 )
  51.             *value++ = *ep++;
  52.  
  53.         goto blank;
  54.         }
  55. endloop: ;
  56.     }
  57.  
  58. blank:
  59.     while( --vlen >= 0 )
  60.         *value++ = ' ';
  61.         
  62. #endif    /* TPM_F2C, SPM_F2C, CW_F2C and MPW_CW_F2C */
  63. }
  64.